package com.hpf.springcloud.config;

import org.springframework.cloud.gateway.route.RouteLocator;
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @description: 路由配置
 * @datetime: 2020/10/24 15:06
 * @author: huangpengfei
 */
//@Configuration
public class GatewayConfig {

    /**
     *  path为访问地址
     *  uri 为需要访问的地址
     * @param routeLocatorBuilder:
     * @return org.springframework.cloud.gateway.route.RouteLocator
     * @author  huangpengfei
     * @datetime  2020/10/24 15:13
     */
//    @Bean
    public RouteLocator customRouteLocatorOne(RouteLocatorBuilder routeLocatorBuilder) {
        RouteLocatorBuilder.Builder routes = routeLocatorBuilder.routes();
        RouteLocator routeOne = routes.route("path_route_one",
                predicateSpec -> predicateSpec.path("/guonei")
                        .uri("http://news.baidu.com/guoji")).build();
        return routeOne;
    }

//    @Bean
    public RouteLocator customRouteLocatorTwo(RouteLocatorBuilder routeLocatorBuilder) {
        RouteLocatorBuilder.Builder routes = routeLocatorBuilder.routes();
        RouteLocator routeOne = routes.route("path_route_one",
                predicateSpec -> predicateSpec.path("/guoji")
                        .uri("http://news.baidu.com/guoji")).build();
        return routeOne;
    }
}
